package game.engine;


import java.awt.Graphics2D;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

public abstract class AbstractEngine implements KeyListener {
	private AbstractEngine nextEngine = null;
	private AbstractEngine previousEngine = null;
	private boolean isReturnAble = false;

	public AbstractEngine getNextEngine() {
		return nextEngine;
	}

	public AbstractEngine getPreviousEngine() {
		return previousEngine;
	}

	public void initialize() {
		/* NOP */
	}

	public boolean isReturnAble() {
		return isReturnAble;
	}

	@Override
	public abstract void keyPressed(KeyEvent e);

	// public abstract void afterRenderSettings();

	@Override
	public abstract void keyReleased(KeyEvent e);

	@Override
	public abstract void keyTyped(KeyEvent e);

	public abstract void render(Graphics2D g2d);

	public void returnToPreviousEngine() {
		AbstractEngine engine = getPreviousEngine();
		if (engine == null) {
			engine = MainMenuEngine.singleton();
		}
		setNextEngine(engine);
	}

	public void setNextEngine(AbstractEngine engine) {
		if (isReturnAble && engine != null) {
			engine.setPreviousEngine(this);
		}
		this.nextEngine = engine;
	}

	public void setPreviousEngine(AbstractEngine Engine) {
		this.previousEngine = Engine;
	}

	public void setReturnAble(boolean isReturnAble) {
		this.isReturnAble = isReturnAble;
	}

	public abstract void update();
}